<template>
  <el-dialog v-model="visible" :title="!dataForm.id ? $t('add') : $t('update')" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="dataRule" ref="dataFormRef" @keyup.enter="dataFormSubmitHandle()" label-width="120px">
      <el-form-item label="主键" prop="id">
        <el-input v-model="dataForm.id" placeholder="主键"></el-input>
      </el-form-item>
      <el-form-item label="支付编号，大写字母Z+时间戳+两位随机数" prop="payCode">
        <el-input v-model="dataForm.payCode" placeholder="支付编号，大写字母Z+时间戳+两位随机数"></el-input>
      </el-form-item>
      <el-form-item label="订单id" prop="orderId">
        <el-input v-model="dataForm.orderId" placeholder="订单id"></el-input>
      </el-form-item>
      <el-form-item label="订单编号" prop="orderCode">
        <el-input v-model="dataForm.orderCode" placeholder="订单编号"></el-input>
      </el-form-item>
      <el-form-item label="会员id" prop="accountId">
        <el-input v-model="dataForm.accountId" placeholder="会员id"></el-input>
      </el-form-item>
      <el-form-item label="付款金额" prop="payAmount">
        <el-input v-model="dataForm.payAmount" placeholder="付款金额"></el-input>
      </el-form-item>
      <el-form-item label="付款时间" prop="payTime">
        <el-input v-model="dataForm.payTime" placeholder="付款时间"></el-input>
      </el-form-item>
      <el-form-item label="付款方法：offline线下，wxpay微信支付，alipay支付宝支付" prop="payMethod">
        <el-input v-model="dataForm.payMethod" placeholder="付款方法：offline线下，wxpay微信支付，alipay支付宝支付"></el-input>
      </el-form-item>
      <el-form-item label="第三方支付订单号" prop="thirdNo">
        <el-input v-model="dataForm.thirdNo" placeholder="第三方支付订单号"></el-input>
      </el-form-item>
      <el-form-item label="-1支付失败，0支付中，1支付成功" prop="payStatus">
        <el-input v-model="dataForm.payStatus" placeholder="-1支付失败，0支付中，1支付成功"></el-input>
      </el-form-item>
      <el-form-item label="0全款，1第一期，2第二期" prop="payType">
        <el-input v-model="dataForm.payType" placeholder="0全款，1第一期，2第二期"></el-input>
      </el-form-item>
      <el-form-item label="付款成功时间" prop="successTime">
        <el-input v-model="dataForm.successTime" placeholder="付款成功时间"></el-input>
      </el-form-item>
      <el-form-item label="失败原因" prop="failReason">
        <el-input v-model="dataForm.failReason" placeholder="失败原因"></el-input>
      </el-form-item>
    </el-form>
    <template v-slot:footer>
      <el-button @click="visible = false">{{ $t("cancel") }}</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">{{ $t("confirm") }}</el-button>
    </template>
  </el-dialog>
</template>

<script lang="ts">
import { defineComponent, reactive } from "vue";
import baseService from "@/service/baseService";
import { useDebounce } from "@/utils/utils";
export default defineComponent({
  setup() {
    return reactive({
      visible: false,
      dataForm: {
        id: "",
        payCode: "",
        orderId: "",
        orderCode: "",
        accountId: "",
        payAmount: "",
        payTime: "",
        payMethod: "",
        thirdNo: "",
        payStatus: "",
        payType: "",
        successTime: "",
        failReason: ""
      }
    });
  },
  computed: {
    dataRule() {
      return {};
    }
  },
  created() {
    this.dataFormSubmitHandle = useDebounce(this.dataFormSubmitHandle);
  },
  methods: {
    init() {
      this.visible = true;
      this.$nextTick(() => {
        this.$refs["dataFormRef"].resetFields();
        if (this.dataForm.id) {
          this.getInfo();
        }
      });
    },
    // 获取信息
    getInfo() {
      baseService.get("/noc/torderpay/" + this.dataForm.id).then((res) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg);
        }
        this.dataForm = res.data;
      });
    },
    // 表单提交
    dataFormSubmitHandle() {
      this.$refs["dataFormRef"].validate((valid: boolean) => {
        if (!valid) {
          return false;
        }
        (!this.dataForm.id ? baseService.post : baseService.put)("/noc/torderpay", this.dataForm).then((res) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.$message({
            message: this.$t("prompt.success"),
            type: "success",
            duration: 500,
            onClose: () => {
              this.visible = false;
              this.$emit("refreshDataList");
            }
          });
        });
      });
    }
  }
});
</script>
